﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using com.globalwave.a8ext;
using System.Collections.Specialized;

namespace SalePrinting
{
    public partial class AuthorForm : Form
    {
        public String salePrice;
        public OrderPrintingForm orderPrintingForm;


        public AuthorForm()
        {
            InitializeComponent();
        }

        public AuthorForm(OrderPrintingForm orderPrintingForm, DataRowView productRow, string salePrice)
        {
            InitializeComponent();
            //this.productRow = productRow;
            this.orderPrintingForm = orderPrintingForm;
            l_name.Text = productRow["fullname"].ToString();
            l_code.Text = productRow["usercode"].ToString();
            l_lowPrice.Text = productRow["lowestprice"].ToString();
            l_highPrice.Text = productRow["retailprice"].ToString();
            l_salePrice.Text = salePrice;
            l_price.Text = productRow["price"].ToString();
            double l_L = double.Parse(productRow["lowestprice"].ToString());
            double l_P = double.Parse(productRow["price"].ToString());
            double l_H = double.Parse(productRow["retailprice"].ToString());
            double l_R = double.Parse(l_salePrice.Text);
            if (l_R < l_L)
            {
                l_status.Text = "低于最低售价";
                if (l_R < l_P)
                {
                    l_status.Text = "低于成本价";
                }
            }
            if (l_R > l_H)
            {
                l_status.Text = "高于标价";
            }
        }

        private void AuthorForm_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            NameValueCollection criterion = new NameValueCollection();

            criterion.Add("password", this.tb_password.Text);

            string user_id = OrderService.getInstance().getString("select userid from [user] where ", criterion);

            if (String.IsNullOrEmpty(user_id)) {
                MessageBox.Show("授权不通过!") ;
                this.tb_password.Text = "";
                this.tb_password.Focus();
                return ;
            }
            orderPrintingForm.author_user = user_id;
            this.DialogResult = DialogResult.OK;
        }

        private void bt_cancle_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void tb_password_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && this.tb_password.Text != "" ) {

                button1_Click(null, null);
            }
        }

        private void l_status_Click(object sender, EventArgs e)
        {

        }


    }
}
